package com.yanqu.road.server.cmd.activity.jieshi;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.JieShiProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.jieshi.JieShiModule;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_JIESHI_CHANGE_NAME, desc = "更改名字")
public class JieShiChangeNameCmd extends AbstractCommand {

    private String nickName;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        JieShiProto.JieShiChangeNameReqMsg reqMsg = JieShiProto.JieShiChangeNameReqMsg.parseFrom(packet.getBytes());
        nickName = reqMsg.getNickName();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(JieShiModule.class).changeNickName(nickName);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            JieShiProto.JieShiChangeNameRespMsg.Builder respMsg = JieShiProto.JieShiChangeNameRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_JIESHI_CHANGE_NAME, respMsg);
        }
    }
}
